package com.jia.together.controller.front;

import com.jia.together.entity.Resource;
import com.jia.together.service.ResourceService;
import com.jia.together.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/front/resource")
//@CrossOrigin
public class ResourceFrontController {
    @Autowired
    private ResourceService resourceService;

    @GetMapping("/queryList")
    public R queryList(@RequestParam(required = false) String key,@RequestParam(required = false) String categoryId,@RequestParam Long pageNum,@RequestParam Long pageSize){
        Map<String,Object> map = resourceService.queryList(key,categoryId,pageNum,pageSize);
        return R.ok().data(map);
    }
    @GetMapping("/info/{id}")
    public R info(@PathVariable String id){
        Resource resource = resourceService.selectInfoById(id);
        return R.ok().data("data",resource);
    }
    @PostMapping("/publish")
    public R publish(@RequestBody Resource resource){
        resourceService.save(resource);
        return R.ok();
    }
}
